package com.gopay.common.rcs.manager.antiphish.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.gopay.common.domain.rcs.RcsAntiPhishConfEditLog;
import com.gopay.common.domain.rcs.RcsAntiPhishConfGlobal;
import com.gopay.common.rcs.bean.DomainnameCheckStatus;
import com.gopay.common.rcs.bean.OrderIPCheckStatus;
import com.gopay.common.rcs.bean.TimestampCheckStatus;
import com.gopay.common.rcs.bean.VerifyCodeCheckStatus;
import com.gopay.common.rcs.dao.antiphish.RcsAntiPhishEditLogDAO;
import com.gopay.common.rcs.dao.antiphish.RcsAntiPhishingGlobalDAO;
import com.gopay.common.rcs.manager.antiphish.RcsAntiPhishingGlobalManager;

/**
 * 防钓鱼全局配置
 * 
 * @RcsAntiPhishingGlobalManager.java
 * @author liujy
 * @2013-7-23 下午6:35:21 www.gopay.com.cn Inc.All rights reserved.
 */
@Service("rcsAntiPhishingGlobalManager")
public class RcsAntiPhishingGlobalManagerImpl implements RcsAntiPhishingGlobalManager {

    @Resource(name = "rcsAntiPhishingGlobalDAO")
    RcsAntiPhishingGlobalDAO rcsAntiPhishingGlobalDAO;
    
    @Resource(name = "rcsAntiPhishEditLogDAO")
    RcsAntiPhishEditLogDAO rcsAntiPhishEditLogDAO;

    /**
     * 添加,一次插入4条,每条对应一个防钓鱼规则(初始化时才用到)
     * 
     * @param globalConfList
     * @return RcsAntiPhishConfGlobal
     */
    @Override
    @Transactional
    public void saveGlobalConf(List<RcsAntiPhishConfGlobal> globalConfList) {
        for (RcsAntiPhishConfGlobal globalConf : globalConfList) {
            rcsAntiPhishingGlobalDAO.save(globalConf);
        }
    }

    /**
     * 查询 全局配置
     * 
     * @param globalConf
     */
    @Override
    public List<RcsAntiPhishConfGlobal> getGlobalConf() {
        return rcsAntiPhishingGlobalDAO.findAll(RcsAntiPhishConfGlobal.class);
    }

    /**
     * 更新单次配置
     * 
     * @param globalConf
     */
    @Override
    @Transactional
    public void updateGlobalConf(List<RcsAntiPhishConfGlobal> globalConfList,List<RcsAntiPhishConfEditLog> logList) {
        //更新数据
        for (RcsAntiPhishConfGlobal globaldConf : globalConfList) {
        	if(0 == globaldConf.getConfSq()){
        		rcsAntiPhishingGlobalDAO.save(globaldConf);
        	}else{
        		rcsAntiPhishingGlobalDAO.update(globaldConf);
        	}
        }
        //记录日志
        for(RcsAntiPhishConfEditLog log:logList ){
            rcsAntiPhishEditLogDAO.save(log);
        }
    }

    @Override
    public DomainnameCheckStatus getDomainnameCheckStatus(String custId) {
        return rcsAntiPhishingGlobalDAO.getDomainnameCheckStatus(custId);
    }

    @Override
    public TimestampCheckStatus getTimestampCheckStatus(String custId) {
        return rcsAntiPhishingGlobalDAO.getTimestampCheckStatus(custId);
    }

    @Override
    public OrderIPCheckStatus getOrderIPCheckStatus(String custId) {
        return rcsAntiPhishingGlobalDAO.getOrderIPCheckStatus(custId);
    }

    @Override
    public VerifyCodeCheckStatus verifyCodeConfig(String custId) {
        return rcsAntiPhishingGlobalDAO.verifyCodeConfig(custId);
    }

}
